﻿@model DepartmentProfile
@{
    ViewBag.Title = "定制信息管理";      
}

<style type="text/css">
    table.thistable tr td { padding-top: 0px; padding-bottom: 0px; vertical-align: top; }

    fieldset ul { margin: 0px; padding: 0px; list-style: none; }
    legend a { text-decoration: none !important; font-weight: normal; color: #F19149 !important; }
        legend a:hover { color: #fff !important; background: #F19149; }
    #EditFieldSet { display: none; }
    #EditError { display: none; text-align: left; color: red; }
    .readonly { background-color: #ccc; }
</style>

@if (!SiteUser.IsDoctorDepManager)
{
    <p class="error-title">对不起，只有科室主任才可以定制信息！</p>
}
else
{
    <p></p>
    using (Html.BeginForm())
    {
    
    <fieldset style="width: 40%; float: left;">
        <legend>定制信息</legend>
        <table class="width noborder thistable">
            <tr>
                <td width="15%">
                    @Html.EditorFor(model => model.SettingKey, "SelField",
                        new
                        {
                            Selects = new SelectList(new List<SelectListItem>
                            {
                                //new SelectListItem{Text = "患者基本信息", Value="UserInfo"},
                                new SelectListItem{Text = "患者住院记录", Value="EnHospital"}
                            }, "Value", "Text", Model.SettingKey)
                        })
                </td>
                <td width="15%">
                    @Html.EditorFor(model => model.SettingValue, "TxtField")
                </td>
                <td width="15%">
                    @Html.EditorFor(model => model.SettingValueB, "SelField",
                        new
                        {
                            Selects = new SelectList(new List<SelectListItem>
                            {
                                new SelectListItem{Text = "文本", Value="System.String"},
                                new SelectListItem{Text = "整数", Value="System.Int32"},
                                new SelectListItem{Text = "浮点数", Value="System.Double"},
                                new SelectListItem{Text = "日期", Value="System.DateTime"},
                                new SelectListItem{Text = "是/否", Value="System.Boolean"},
                            }, "Value", "Text", Model.SettingKey)
                        })
                </td>
            </tr>
            <tr>
                <td colspan="3">
                    @Html.HiddenFor(model => model.ID)
                    @Html.HiddenFor(model => model.DepartmentID)
                    <div class="editor-label">
                        @Helpers.TryRenderRequiredTag(true)
                        @Html.LabelFor(model => model.SettingValueC)
                    </div>
                    <div class="editor-field">
                        <span class="small-input">
                        @Html.TextBox("SettingValueC", Model.SettingValueC,
                        new
                        {                            
                            onkeyup = @"this.value=this.value.replace(/\D/g,'')",
                            onafterpaste = @"this.value=this.value.replace(/\D/g,'')"
                        })
                        </span>
                        <br />
                        @Html.ValidationMessageFor(model => model.SettingValueC)
                    </div>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    @Html.ValidationSummary(true)
                </td>
                <td>
                    <input type="submit" value="确定" />
                </td>
            </tr>
        </table>
    </fieldset>
    }


    <div id="userInfoFieldList" style="width: 55%; float: right;">
        @Html.Partial("RecuperAttachInfoList", SiteUser.Department.DepartmentProfiles.Where(p => p.SettingKey == "UserInfo" || p.SettingKey == "EnHospital"))
    </div>
    <script type="text/javascript">
        $(function () {
            $('#SettingValueB').change(function () {
                var enabled = ($(this).val() == 'System.String') || ($(this).val() == 'System.Int32')
                    || ($(this).val() == 'System.Double');
                $('#SettingValueC').attr('readonly', !enabled);
                if (!enabled) {
                    $('#SettingValueC').addClass('readonly').val('0');
                } else {
                    $('#SettingValueC').removeClass('readonly');
                    if ($(this).val() == 'System.String') {
                        $('#SettingValueC').val('20');
                    } else if ($(this).val() == 'System.Int32') {
                        $('#SettingValueC').val('5');
                    } else if ($(this).val() == 'System.Double') {
                        $('#SettingValueC').val('8');
                    }
                }
            });
            $('#SettingValueB').change();
        });
    </script>
}
